package cn.com.bdqn.controller;

import cn.com.bdqn.entity.SyCostType;
import cn.com.bdqn.entity.SyEmp;
import cn.com.bdqn.service.SyCostTypeService;
import cn.com.bdqn.utils.ReturnData;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/syCostType")
@Api(tags = "费用类型管理接口")
public class SyCostTypeController {

    @Autowired
    private SyCostTypeService syCostTypeService;

    @Operation(summary = "根据类型 （0用水类型 1附加费）查询费用数据")
    @PostMapping("/queryByKind")
    public ReturnData queryByKind(Long kind){
        try {
            List<SyCostType> syCostTypes = syCostTypeService.queryByKind(kind);
            return ReturnData.ok().put("syCostTypes",syCostTypes);
        }catch (Exception e){
            return ReturnData.currError("根据类型 （0用水类型 1附加费）查询费用数据数据库异常");
        }
    }

    @Operation(summary = "根据ID查询费用数据")
    @PostMapping("/queryById")
    public ReturnData queryById(Long id){
        try {
            SyCostType syCostType = syCostTypeService.queryById(id);
            return ReturnData.ok().put("syCostType",syCostType);
        }catch (Exception e){
            return ReturnData.currError("根据ID查询费用数据数据库异常");
        }
    }

    @Operation(summary = "新增费用信息")
    @PostMapping("/addSyCostType")
    public ReturnData addSyCostType(SyCostType syCostType){
        int result = syCostTypeService.addSyCostType(syCostType);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("新增费用信息数据库异常");
        }
    }

    @Operation(summary = "修改费用信息")
    @PostMapping("/updateSyCostType")
    public ReturnData updateSyCostType(SyCostType syCostType){
        int result = syCostTypeService.updateSyCostType(syCostType);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("修改费用信息数据库异常");
        }
    }

}
